#include <string>
#include <thread>
#define private public
#include "double_buffer.h"
#undef private
#include "gtest/gtest.h"

namespace Base {
namespace SystemLog {
using namespace std::chrono_literals;
namespace {
constexpr size_t TEST_MESSAGE_SIZE_256 = 256;
constexpr int32_t TEST_MESSAGE_COUNT = 10000;
const char TEST_CHAR = 't';
} // namespace

class DoubleBufferSecurityTest : public testing::Test {
public:
    static void SetUpTestCase(void) {}
    static void TearDownTestCase(void) {}
    void SetUp() {}
    void TearDown() {}
};

/**
 * @tc.name: DoubleBufferSecurityTest_001
 * @tc.desc: memory leak detection
 * @tc.type: SECURITY
 */
TEST_F(DoubleBufferSecurityTest, DoubleBufferSecurityTest_001)
{
    {
        DoubleBuffer<> doubleBuffer;
        const std::string msg(TEST_MESSAGE_SIZE_256, TEST_CHAR);
        for (int i = 0; i < TEST_MESSAGE_COUNT; ++i) {
            doubleBuffer.Append(msg.c_str(), msg.size());
        }
        doubleBuffer.SafeSwap();
        // 不释放节点，测试内存泄漏
    }
}

} // namespace SystemLog
} // namespace Base
